/*
 * IntervalSlider.java
 *
 * Created on July 9, 2008, 7:22 PM
 */

package anivis.ui.timeline;

import anivis.base.TimeInterval;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.util.Date;
import java.util.GregorianCalendar;
/**
 *
 * @author  urp
 */
public class IntervalSlider extends javax.swing.JComponent {
    
    private Date         curTime;
    private TimeInterval curTimeWindow;
    private TimeInterval curTimeSpan;
    
    /** Creates new form IntervalSlider */
    public IntervalSlider() {
        initComponents();
        
        curTime       = new GregorianCalendar(1900,1,1).getTime();
        curTimeSpan   = new TimeInterval(new GregorianCalendar(1900,1,1).getTime(),
                                         new GregorianCalendar(2000,1,1).getTime() );
        curTimeWindow = new TimeInterval(new GregorianCalendar(1940,1,1).getTime(),
                                         new GregorianCalendar(1960,1,1).getTime() );
    }         
    
    public Date getCurrentTime() {
        return curTime;
    }
    
    public void setCurrentTime(Date date) {
        curTime = date;
    }
    
    public TimeInterval getTimeWindow() 
    {
        return curTimeWindow;
    }

    public void setTimeWindow(TimeInterval interval) 
    {
        curTimeWindow=interval;
    } 

    
    public TimeInterval getTimeSpan() 
    {
        return curTimeSpan;
    }

    public void setTimeSpan(TimeInterval interval) 
    {
        curTimeSpan=interval;
    } 

    @Override
    public void paintComponent(Graphics g)
    {
      super.paintComponent(g);
      Graphics2D g2d      = (Graphics2D) g;
      
      if(getTimeSpan().contains(getTimeWindow().getBegin()))
      {
          float posCenter =   getWidth() 
                            * (getCurrentTime().getTime()-getTimeSpan().getBeginTime()) 
                            / getTimeSpan().getLengthInMillis();
            
          Polygon    curTimeIndicator = new Polygon();
          curTimeIndicator.addPoint(0,0);
          curTimeIndicator.addPoint(10,10);
          curTimeIndicator.addPoint(20, 0);

          g2d.drawPolygon(curTimeIndicator);
      }//else
      
      if(getTimeSpan().contains(getTimeWindow().getBegin()))
      {
          float posLeft   =    getWidth() 
                        * (getTimeWindow().getBeginTime()-getTimeSpan().getBeginTime()) 
                        / getTimeSpan().getLengthInMillis();
      
          Polygon    leftBoundIndicator = new Polygon();
          leftBoundIndicator.addPoint(10,0);
          leftBoundIndicator.addPoint(10,10);
          leftBoundIndicator.addPoint(20, 0);
          
          g2d.drawPolygon(leftBoundIndicator);      
//        g2d.drawLine();
  
      }//else
       //   g2d.drawLine();
      
      if(getTimeSpan().contains(getTimeWindow().getEnd()))
      {
          float posRight   =    getWidth() 
                        * (getTimeWindow().getEndTime()-getTimeSpan().getBeginTime()) 
                        / getTimeSpan().getLengthInMillis();

          Polygon    rightBoundIndicator = new Polygon();
          rightBoundIndicator.addPoint(0,0);
          rightBoundIndicator.addPoint(10,10);
          rightBoundIndicator.addPoint(10, 0);

          g2d.drawPolygon(rightBoundIndicator);
//        g2d.drawLine();
      }//else
       //   g2d.drawLine
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    setName("Form"); // NOI18N

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(0, 627, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(0, 306, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents


  // Variables declaration - do not modify//GEN-BEGIN:variables
  // End of variables declaration//GEN-END:variables

}
